package org.grottarossa.ui.core.casemanagement.contents;

import java.util.ResourceBundle;

import org.grottarossa.template.data.pojo.content.Content;
import org.grottarossa.template.data.pojo.table.Record;
import org.grottarossa.ui.core.ApplicationSession;
import org.grottarossa.ui.core.base.BasePanel;
import org.grottarossa.ui.core.controls.document.DocumentVersionsManager;
import org.grottarossa.ui.core.controls.document.DocumentVersionsManagerFactory;
import org.grottarossa.ui.core.i18n.DM;
import org.grottarossa.ui.core.layout.LayoutFactory;


import com.vaadin.data.util.BeanItem;
import com.vaadin.terminal.ExternalResource;
import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.Component;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.Layout;
import com.vaadin.ui.Link;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window.Notification;

/***
 * Rappresenta il dettaglio di un content
 * @author 
 */
public class ContentPanel extends BasePanel
{
	private static final long serialVersionUID = -799416696090582197L;
	private final Content m_content;
	private VerticalLayout m_contentPanel;

	public ContentPanel(ApplicationSession appSession, Content content) throws Exception
	{
		super(appSession, DM.instance().getBundle(ContentPanel.class.getName()));
		this.m_content = content;
		this.m_contentPanel = initLayout();
		initializeComponents();
	}

	@Override
	protected void initializeComponents()
	{
		getLayout().setWidth(100, Sizeable.UNITS_PERCENTAGE);
		getLayout().setHeight(100, Sizeable.UNITS_PERCENTAGE);

		DocumentVersionsManagerFactory f = new DocumentVersionsManagerFactory(m_appSession);
		DocumentVersionsManager dvm = f.createVersionsManager(m_content);
		dvm.setWidth(100, Sizeable.UNITS_PERCENTAGE);
		dvm.setHeight(100, Sizeable.UNITS_PERCENTAGE);

		HorizontalSplitPanel sp = new HorizontalSplitPanel();
		sp.setWidth(100, Sizeable.UNITS_PERCENTAGE);
		sp.setHeight(100, Sizeable.UNITS_PERCENTAGE);

		sp.setFirstComponent(m_contentPanel);
		sp.setSecondComponent(dvm);

		addComponent(sp);
	}

	private VerticalLayout initLayout() throws Exception
	{
		VerticalLayout contentPanel = new VerticalLayout();

		HorizontalLayout buttonsBar = new HorizontalLayout();

		Component panel = (Component) m_appSession.getLayoutFactory().createLayout(
				"DocumentVersionsManager", new Class[] { Record.class, Layout.class},  new Object[] { m_content.getDocumentID(), buttonsBar} );

		panel.setWidth(100, Sizeable.UNITS_PERCENTAGE);
		panel.setHeight(100, Sizeable.UNITS_PERCENTAGE);

		contentPanel.addComponent(panel);
		contentPanel.addComponent(buttonsBar);
		contentPanel.setExpandRatio(panel, 1000);
		contentPanel.setExpandRatio(buttonsBar, 1);

		contentPanel.setWidth(100, Sizeable.UNITS_PERCENTAGE);
		contentPanel.setHeight(100, Sizeable.UNITS_PERCENTAGE);
		return contentPanel;
	}
}
